<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get a semaphore id</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sem-acquire.html">sem_acquire</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sem-release.html">sem_release</a></div>
 <div class="up"><a href="ref.sem.html">Semaphore 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.sem-get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sem_get</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">sem_get</span> &mdash; <span class="dc-title">Get a semaphore id</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.sem-get-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>sem_get</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$key</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_acquire</code><span class="initializer"> = 1</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$perm</code><span class="initializer"> = 0666</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$auto_release</code><span class="initializer"> = 1</span></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>sem_get()</strong></span> returns an id that can be used to
   access the System V semaphore with the given <em><code class="parameter">key</code></em>.
  </p>
  <p class="para">
   A second call to <span class="function"><strong>sem_get()</strong></span> for the same key
   will return a different semaphore identifier, but both
   identifiers access the same underlying semaphore.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sem-get-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">key</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">max_acquire</code></em></dt>

     <dd>

      <p class="para">
       The number of processes that can acquire the semaphore simultaneously
       is set to <em><code class="parameter">max_acquire</code></em>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">perm</code></em></dt>

     <dd>

      <p class="para">
       The semaphore permissions. Actually this value is
       set only if the process finds it is the only process currently
       attached to the semaphore.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">auto_release</code></em></dt>

     <dd>

      <p class="para">
       Specifies if the semaphore should be automatically released on request
       shutdown.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sem-get-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a positive semaphore identifier on success, or <strong><code>FALSE</code></strong> on
   error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.sem-get-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.0</td>
       <td>
        The <em><code class="parameter">auto_release</code></em> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.sem-get-notes">
  <h3 class="title">注释</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    When using <span class="function"><strong>sem_get()</strong></span> to access a semaphore created
    outside PHP, note that the semaphore must have been created as a set of 3
    semaphores (for example, by specifying 3 as the <em>nsems</em>
    parameter when calling the C <em>semget()</em> function),
    otherwise PHP will be unable to access the semaphore.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sem-get-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.sem-acquire.html" class="function" rel="rdfs-seeAlso">sem_acquire()</a> - Acquire a semaphore</span></li>
    <li class="member"><span class="function"><a href="function.sem-release.html" class="function" rel="rdfs-seeAlso">sem_release()</a> - Release a semaphore</span></li>
    <li class="member"><span class="function"><a href="function.ftok.html" class="function" rel="rdfs-seeAlso">ftok()</a> - Convert a pathname and a project identifier to a System V IPC key</span></li>
   </ul>
  </p>
 </div>
  

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sem-acquire.html">sem_acquire</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sem-release.html">sem_release</a></div>
 <div class="up"><a href="ref.sem.html">Semaphore 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
